﻿#region Copyright (c) Koolwired Solutions, LLC.
/*--------------------------------------------------------------------------
 * Copyright (c) 2009, Koolwired Solutions, LLC.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer. 
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution. 
 * Neither the name of Koolwired Solutions, LLC. nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission. 
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
 * AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 *--------------------------------------------------------------------------*/
#endregion

#region History
/*--------------------------------------------------------------------------
 * Modification History: 
 * Date       Programmer      		Description
 * 12/18/09   Keith Kikta     		Inital release.
 *--------------------------------------------------------------------------*/
#endregion

#region References
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
#endregion

namespace Koolwired.Imap.DiagnosticTool
{
    #region Header
    /// <summary>
    /// Represents the connection properties form.
    /// </summary>
    #endregion
    public partial class ConnectionProperties : Form
    {
        #region Public Properties
        /// <summary>
        /// Gets or sets a string containing the hostname or ip address.
        /// </summary>
        public string Host
        {
            get;
            set;
        }
        /// <summary>
        /// Gets or sets a string containing user name.
        /// </summary>
        public string User
        {
            get;
            set;
        }
        /// <summary>
        /// Gets or sets a integer representing the tcp port to connect to.
        /// </summary>
        public int Port
        {
            get;
            set;
        }
        /// <summary>
        /// Gets or sets a boolean indicating if this is a SSL connection.
        /// </summary>
        public bool IsSSL
        {
            get;
            set;
        }
        #endregion

        #region Constructor
        /// <summary>
        /// Creates an instance of the connection properties form.
        /// </summary>
        public ConnectionProperties()
        {
            InitializeComponent();
            PreLoad();
            Load();
        }
        #endregion

        #region Private Variables
        /// <summary>
        /// Process save button from connection properties form.
        /// </summary>
        /// <param name="sender">An object representing the calling control.</param>
        /// <param name="e">A EventArgs object.</param>
        void button1_Click(object sender, EventArgs e)
        {
            this.Host = txtHost.Text;
            this.User = txtUser.Text;
            this.Port = int.Parse(txtPort.Text);
            this.IsSSL = chbSSL.Checked;
            Save();
            this.Hide();
        }
        /// <summary>
        /// Load properties from user settings file.
        /// </summary>
        void PreLoad()
        {
            Properties.Settings.Default.Reload();
            this.Host = Properties.Settings.Default.Host;
            this.User = Properties.Settings.Default.Username;
            this.Port = Properties.Settings.Default.Port;
            this.IsSSL = Properties.Settings.Default.IsSSL;
        }
        /// <summary>
        /// Load values from properties.
        /// </summary>
        void Load()
        {
            txtHost.Text = this.Host;
            txtUser.Text = this.User;
            txtPort.Text = this.Port.ToString();
            chbSSL.Checked = this.IsSSL;
        }
        /// <summary>
        /// Save the settings to the user settings file.
        /// </summary>
        void Save()
        {
            Properties.Settings.Default.Host = this.Host;
            Properties.Settings.Default.Username = this.User;
            Properties.Settings.Default.Port = this.Port;
            Properties.Settings.Default.IsSSL = this.IsSSL;
            Properties.Settings.Default.Save();
        }
        #endregion
    }
}
